---
title: Tavily
---

**TavilyTools** enable an Agent to search the web using the Tavily API.

## Prerequisites

The following examples requires the `tavily-python` library and an API key from [Tavily](https://tavily.com/).

```shell
pip install -U tavily-python
```

```shell
export TAVILY_API_KEY=***
```

## Example

The following agent will run a search on Tavily for "language models" and print the response.

```python cookbook/tools/tavily_tools.py
from agno.agent import Agent
from agno.tools.tavily import TavilyTools

agent = Agent(tools=[TavilyTools()])
agent.print_response("Search tavily for 'language models'", markdown=True)
```

## Toolkit Params

| Parameter             | Type                           | Default      | Description                                                                                   |
| --------------------- | ------------------------------ | ------------ | --------------------------------------------------------------------------------------------- |
| `api_key`             | `Optional[str]`                | `None`       | Tavily API key. If not provided, will use TAVILY_API_KEY environment variable.              |
| `enable_search`       | `bool`                         | `True`       | Enable search functionality.                                                                 |
| `enable_search_context` | `bool`                       | `False`      | Enable search context functionality using Tavily's context API.                             |
| `all`                 | `bool`                         | `False`      | Enable all available functions in the toolkit.                                               |
| `max_tokens`          | `int`                          | `6000`       | Maximum number of tokens to use in search results.                                           |
| `include_answer`      | `bool`                         | `True`       | Whether to include an AI-generated answer summary in the response.                           |
| `search_depth`        | `Literal['basic', 'advanced']` | `'advanced'` | Depth of search - 'basic' for faster results or 'advanced' for more comprehensive search.   |
| `format`              | `Literal['json', 'markdown']`  | `'markdown'` | Output format - 'json' for raw data or 'markdown' for formatted text.                       |

## Toolkit Functions

| Function                  | Description                                                                                                                                                                                              |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `web_search_using_tavily` | Search the web for a given query using Tavily API. Parameters include `query` (str) for the search query and `max_results` (int, default=5) for maximum number of results. Returns JSON string of results with titles, URLs, content and relevance scores in specified format. |
| `web_search_with_tavily`  | Alternative search function that uses Tavily's search context API. Parameters include `query` (str) for the search query. Returns contextualized search results. Only available when `enable_search_context` is True. |

## Developer Resources

- View [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/tavily.py)
- View [Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/tools/tavily_tools.py)
